/**
 * Created by 55456 on 2016/4/17.
 */
var router = require("express").Router();
var fs = require("fs");
var path = require("path");
var Cache = require("../instance/cache");
var cache = new Cache();

router.use((req,res,next) => {
    req.app.locals.cache = cache;
    next();
});

var loadDir = (dir) => {
    fs
        .readdirSync(dir)
        .forEach( (file) => {
            var nextPath = path.join(dir, file);
            var stat = fs.statSync(nextPath);
            if (stat.isDirectory()) {
                loadDir(nextPath);
            } else if (stat.isFile() && file.indexOf('.') !== 0 && file !== 'index.js') {
                require(nextPath)(router);
            }
        });
};

loadDir(__dirname);

module.exports = router;


